package laki.action;

import java.sql.Connection;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import laki.service.LoginService;
import laki.util.DatabaseCon;

public class LoginAction {
	private String username;
	private String password;
	public String execute(){
		 Map session = ActionContext.getContext().getSession();
		 DatabaseCon connector = new DatabaseCon();
		 Connection con = connector.databaseConnctor(getUsername(), getPassword());
		 LoginService loginService = new LoginService();
		 String result = loginService.confirmCredentials(con);
		if(result.equals("success")|| session.containsKey("logged-in"))
			return "sucess";
		else
			return "error";
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
}
